<?php

$INSTALL_DIR = dirname(dirname(__FILE__)).'/';

$config = array(
	'dir.install'    => $INSTALL_DIR,
	'dir.localstate' => $INSTALL_DIR.'var/',
	'dir.cache'      => $INSTALL_DIR.'var/cache',
);

class TestCase
{
	public function assertIsDir ($path, $message=NULL)
	{
		if (is_dir($path)) { $this->success($message, sprintf('"%s" директория', $path)); }
		else { $this->fail($message, sprintf('"%s" не является директорией', $path)); }
	} // end of method assertTrue
	public function assertTrue ($boolean, $message=NULL)
	{
		if ($boolean) { $this->success($message); }
		else { $this->fail($message); }
	} // end of method assertTrue
	public function runTest ($test_name)
	{
		$test_title = $test_name . '_title';
		$this->test_name = $test_name;
		$this->test_title = isset($this->$test_title) ? $this->$test_title : $test_name;
		$this->$test_name();
	} // end of method runTest
	public function success ($message, $internal_message)
	{
		echo sprintf("%s %s [Ok]\n", $this->test_title, ($message ? $message : $internal_message));
	} // end of method success
	public function fail ($message, $internal_message)
	{
		echo sprintf("%s %s [Fail]\n", $this->test_title, ($message ? $message : $internal_message));
	} // end of function fail
	public function getTests ()
	{
		$methods = get_class_methods($this);
		$res = array();
		foreach ($methods as $method) {
			if (substr($method, 0, 5) === 'test_') {
				$res[] = $method;
			}
		}
		return $res;
	} // end of method getTests
	public function run ()
	{
		echo sprintf("%s\n", $this->title);
		$tests = $this->getTests();
		foreach ($tests as $test) {
			$this->runTest($test);
		}
	} // end of method run
}

class InstallTestCase extends TestCase
{
	public $title = 'Проверка документов';
	public function __construct ($config)
	{
		$this->config = $config;
	} // end of __construct

	public $test_dir_install_title = 'паспорт';
	function test_dir_install()
	{
		$value = $this->config['dir.localstate'];
		$this->assertIsDir($value);
	} // end of function check_pre_dir_var
}

ob_start();


$test = new InstallTestCase($config);
echo '<pre>';
$test->run();
echo '</pre>';

$body = ob_get_clean();
if (!$body) $body = 'Привет';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<title>Platonica installer</title>
</head>
<body id="body"><?=$body?></body>
</html>

